import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : cww
 * @date : 2021/1/11 23:09
 */
public class ChessFactory {
    private static HashMap<String, List<Chess>> chessListMap = new HashMap<>();
    public static Chess getChess(String color){
        List<Chess> chessList = chessListMap.get(color);
        Chess chess;
        if(chessList==null){
            chessList = new ArrayList<>();
            chess = new Chess(color);
            chessList.add(chess);
            chessListMap.put(color,chessList);
        }else {
            List<Chess> canUserChess = chessList.stream().filter(t->t.getState()=="0").
                    collect(Collectors.toList());
            if(canUserChess.size()>0){
                chess = canUserChess.get(0);
                chess.setState("1");
            }else {
                chess = new Chess(color);
                chessList.add(chess);
            }

        }
        return chess;
    }

}
